﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WeifenLuo.WinFormsUI.Docking;
using System.Drawing;
using SignalBox.Core.Model;

namespace SignalBoxSimulator
{
    public class TrainList : DockContent
    {
        private System.Windows.Forms.DataGridView dataGridView1;
        private System.Windows.Forms.BindingSource trainBindingSource;
        private System.Windows.Forms.DataGridViewTextBoxColumn Code;
        private System.Windows.Forms.DataGridViewTextBoxColumn Entry;
        private System.Windows.Forms.DataGridViewTextBoxColumn EntryPoint;
        private System.Windows.Forms.DataGridViewTextBoxColumn ExitPoint;
        private System.Windows.Forms.DataGridViewTextBoxColumn Exit;
        private System.Windows.Forms.DataGridViewTextBoxColumn stateDataGridViewTextBoxColumn;
        private System.ComponentModel.IContainer components;


        private TrainDetails trainDetails;

        public TrainList(TrainDetails td)
            
        {
            InitializeComponent();

            trainDetails = td;
        }

        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle();
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle();
            this.dataGridView1 = new System.Windows.Forms.DataGridView();
            this.Code = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Entry = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.EntryPoint = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.ExitPoint = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Exit = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.stateDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.trainBindingSource = new System.Windows.Forms.BindingSource(this.components);
            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.trainBindingSource)).BeginInit();
            this.SuspendLayout();
            // 
            // dataGridView1
            // 
            this.dataGridView1.AllowUserToAddRows = false;
            this.dataGridView1.AllowUserToDeleteRows = false;
            this.dataGridView1.AutoGenerateColumns = false;
            this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.Code,
            this.Entry,
            this.EntryPoint,
            this.ExitPoint,
            this.Exit,
            this.stateDataGridViewTextBoxColumn});
            this.dataGridView1.DataSource = this.trainBindingSource;
            this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.dataGridView1.Location = new System.Drawing.Point(0, 0);
            this.dataGridView1.Name = "dataGridView1";
            this.dataGridView1.ReadOnly = true;
            this.dataGridView1.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
            this.dataGridView1.Size = new System.Drawing.Size(722, 427);
            this.dataGridView1.TabIndex = 0;
            this.dataGridView1.SelectionChanged += new System.EventHandler(this.dataGridView1_SelectionChanged);
            // 
            // Code
            // 
            this.Code.DataPropertyName = "Code";
            this.Code.HeaderText = "Code";
            this.Code.Name = "Code";
            this.Code.ReadOnly = true;
            // 
            // Entry
            // 
            this.Entry.DataPropertyName = "Entry";
            dataGridViewCellStyle3.Format = "t";
            dataGridViewCellStyle3.NullValue = null;
            this.Entry.DefaultCellStyle = dataGridViewCellStyle3;
            this.Entry.HeaderText = "Entry";
            this.Entry.Name = "Entry";
            this.Entry.ReadOnly = true;
            // 
            // EntryPoint
            // 
            this.EntryPoint.DataPropertyName = "EntryPoint";
            this.EntryPoint.HeaderText = "Entry Point";
            this.EntryPoint.Name = "EntryPoint";
            this.EntryPoint.ReadOnly = true;
            // 
            // ExitPoint
            // 
            this.ExitPoint.DataPropertyName = "ExitPoint";
            this.ExitPoint.HeaderText = "Exit Point";
            this.ExitPoint.Name = "ExitPoint";
            this.ExitPoint.ReadOnly = true;
            // 
            // Exit
            // 
            this.Exit.DataPropertyName = "Exit";
            dataGridViewCellStyle4.Format = "t";
            this.Exit.DefaultCellStyle = dataGridViewCellStyle4;
            this.Exit.HeaderText = "Exit";
            this.Exit.Name = "Exit";
            this.Exit.ReadOnly = true;
            // 
            // stateDataGridViewTextBoxColumn
            // 
            this.stateDataGridViewTextBoxColumn.DataPropertyName = "State";
            this.stateDataGridViewTextBoxColumn.HeaderText = "State";
            this.stateDataGridViewTextBoxColumn.Name = "stateDataGridViewTextBoxColumn";
            this.stateDataGridViewTextBoxColumn.ReadOnly = true;
            // 
            // trainBindingSource
            // 
            this.trainBindingSource.DataSource = typeof(SignalBox.Core.Model.TrainInfo);
            // 
            // TrainList
            // 
            this.ClientSize = new System.Drawing.Size(722, 427);
            this.Controls.Add(this.dataGridView1);
            this.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.Name = "TrainList";
            this.Text = "Schedule";
            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.trainBindingSource)).EndInit();
            this.ResumeLayout(false);

        }
        public List<TrainInfo> Trains
        {
            set
            {
                trainBindingSource.DataSource = value;
                dataGridView1.Refresh();
            }
        }

        

        private void dataGridView1_SelectionChanged(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count == 0) return;

            TrainInfo ti = (TrainInfo)dataGridView1.SelectedRows[0].DataBoundItem;
            trainDetails.TrainInfo = ti;
        }
    }
}
